<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            position: relative;
        }
        .dd {
            width: 100%;
            height: 800px;
            border: 1px solid red;
            display: flex;
            justify-content: center;
            align-items: center;
            /* 
            display: flex; 声明这个是flex布局
            justify-content: center; 水平
            align-items: center; 垂直 
            */
        }
        .box {
            border: 1px solid #fff;
            width: 200px;
            height: 200px;
            background-color: pink;
            position: absolute;
            display: flex;
            justify-content: center;
        }

        .login {
            width: 200px;
            height: 50px;
            background-color: purple;
        }
        .c{
            clear: both;
            height: 0;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div class="dd">
        <div class="box">
            <div class="login"></div>
        </div>
    </div>
    <script>
        var box = document.querySelector('.box');
        var login = document.querySelector('.login');
        login.addEventListener('mousedown', function(e) {
            var x = e.pageX  - box.offsetLeft;
            var y = e.pageY  - box.offsetTop;

            document.addEventListener('mousemove', move);

            function move(e) {
                /* left_ = e.pageX - x + "px";
                top_ = e.pageY - y + "px"; */
                box.style.left = e.pageX - x + "px"; 
                box.style.top = e.pageY - y + "px"; 
            }

            document.addEventListener('mouseup', function() {
                document.removeEventListener('mousemove',move);
            })
        })
    </script>
</body>
</html>